package com.zbkj.service.model.dto;

import com.zbkj.dal.base.enums.FundTradeTypeEnums;
import com.zbkj.dal.base.enums.ShareProfitSceneEnums;
import com.zbkj.dal.entity.profit.ShareProfitRecord;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Objects;

@Data
public class FundUpdateDTO {

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 图片
     */
    private String image;

    /**
     * 业务单号
     */
    private String bizOrderNo;

    /**
     * 变动金额
     */
    private BigDecimal amount;

    /**
     * 业务类型
     *
     * @see FundTradeTypeEnums
     */
    private String tradeType;

    /**
     * 备注
     */
    private String remark;

    public static FundUpdateDTO generateShareProfit(ShareProfitRecord shareProfitRecord) {
        FundUpdateDTO fundUpdateDTO = new FundUpdateDTO();
        fundUpdateDTO.setUserId(Integer.valueOf(shareProfitRecord.getPayeeCode()));
        fundUpdateDTO.setBizOrderNo(shareProfitRecord.getShareProfitNo());
        fundUpdateDTO.setAmount(shareProfitRecord.getRealAmount());
        fundUpdateDTO.setImage(shareProfitRecord.getImagePath());
        fundUpdateDTO.setTradeType(FundTradeTypeEnums.SHARE_PROFIT.getCode());
        if (Objects.equals(shareProfitRecord.getSceneCode(), ShareProfitSceneEnums.RECRUIT.getCode())) {
            fundUpdateDTO.setImage("/sxwxapp/static/images/meta/default/balance-recuit-reward.png");
            fundUpdateDTO.setRemark("新朋友：" + shareProfitRecord.getSourceUserName());
        } else if (StringUtils.equals(String.valueOf(shareProfitRecord.getSourceUserId()), shareProfitRecord.getPayeeCode())) {
            fundUpdateDTO.setRemark(shareProfitRecord.getSourceUserName() + "订单：" + shareProfitRecord.getBizOrderNo());
        } else {
            fundUpdateDTO.setRemark(shareProfitRecord.getSourceUserName() + " | 订单：" + shareProfitRecord.getBizOrderNo());
        }
        return fundUpdateDTO;
    }

}
